const app = getApp()

Page({
    data: {
      videoInfo: "default"
    },
    //登录方法
    doLogin:function(e){
      var me = this;
      var formObject = e.detail.value;
      var username = formObject.username;
      var password = formObject.password;
      if(username.length == 0 || password.length ==0){
        wx.showToast({
          title: '用户名或密码不能为空',
          icon: 'none',
          duration: 3000
        })
      }else{
        var url = app.serverUrl;
        //提示用户请求已发送
        wx.showLoading({
          title: '请等待...'
        })
        //调用请求接口
        wx.request({
          url: url+'/login',
          method: 'POST',
          data: {
            username: username,
            password: password
          },
          header: {
            'content-type': 'application/json' 
          },
          //接口调用成功
          success:function (res) {
            wx.hideLoading();
            var status = res.data.status;
            if(status == 200){
              //app.userInfo = res.data.data;
              //使用缓存的方式
              app.setGlobalUserInfo(res.data.data);
              //看到底该跳转到哪里
              var videoInfo = me.data.videoInfo;
              if(videoInfo == "default" || videoInfo == undefined || videoInfo == null || videoInfo == ''){
                wx.navigateTo({
                  url: '../mine/mine'
                })
                
              }else{
                var videoInfo = me.data.videoInfo;
                console.log(videoInfo)
                wx.redirectTo({
                  url: '../videoInfo/videoInfo?videoInfo='+videoInfo,
                })
              }
              
            }else if(status == 500){
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })

            }
          }   
        })
      }
    },

    //页面跳转->注册页
    goRegistPage: function(){
      wx.navigateTo({
        url: '../userRegister/register'
      })
    },
    onLoad: function(params){
      var me = this;
      if(params == null || params == undefined || params =='' ){
        //do nothing
      }{
      var videoInfo = params.info;
      me.setData({
        videoInfo: videoInfo
      })
      }
      
      
    }
})